<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>调试测试页面</title>
</head>
<body>
    <h1>调试测试页面</h1>
    <div id="status">正在测试...</div>
    <div id="result"></div>
    
    <script>
        // 测试API调用
        async function testAPI() {
            const statusDiv = document.getElementById('status');
            const resultDiv = document.getElementById('result');
            
            try {
                statusDiv.textContent = '正在测试API...';
                
                // 测试机器数据API
                const machinesResponse = await fetch('/api/monitor/machines');
                console.log('Machines API response status:', machinesResponse.status);
                
                if (machinesResponse.ok) {
                    const machinesData = await machinesResponse.json();
                    console.log('Machines data:', machinesData);
                    resultDiv.innerHTML += '<p>✅ 机器数据API正常，返回 ' + machinesData.length + ' 台机器</p>';
                } else {
                    resultDiv.innerHTML += '<p>❌ 机器数据API失败: ' + machinesResponse.status + '</p>';
                }
                
                // 测试待翻品种计划API
                const plansResponse = await fetch('/api/monitor/pending-plans');
                console.log('Plans API response status:', plansResponse.status);
                
                if (plansResponse.ok) {
                    const plansData = await plansResponse.json();
                    console.log('Plans data:', plansData);
                    resultDiv.innerHTML += '<p>✅ 待翻品种计划API正常</p>';
                } else {
                    resultDiv.innerHTML += '<p>❌ 待翻品种计划API失败: ' + plansResponse.status + '</p>';
                }
                
                statusDiv.textContent = '测试完成';
                
            } catch (error) {
                console.error('API测试错误:', error);
                resultDiv.innerHTML += '<p>❌ API测试错误: ' + error.message + '</p>';
                statusDiv.textContent = '测试失败';
            }
        }
        
        // 页面加载完成后执行测试
        document.addEventListener('DOMContentLoaded', function() {
            console.log('页面加载完成，开始测试...');
            testAPI();
        });
    </script>
</body>
</html>
